Component({
  properties: {
    show: {
      type: Boolean,
      value: false
    },
    columns: {
      type: Array,
      value: []
    },
    labelKey: {
      type: String,
      value: 'label'
    }
  },
  data: {
    currentItem: {}
  },
  methods: {
    select ({ currentTarget: { dataset: { item } } }) {
      this.setData({ currentItem: item })
    },
    close () {
      this.triggerEvent('close')
    },
    async confirm () {
      try {
        this.triggerEvent('change', this.data.currentItem)
      } catch (err) {
        wx.showToast({ title: err.message || err.ResultSet.errors, icon: 'none' })
      }
    }
  },
})